package com.betterwood.dragon.enums;

import cn.hutool.core.util.StrUtil;

import java.util.HashMap;
import java.util.Map;

public enum OrderStatusEnum {

    PRE("预生成"),
    INIT("未完成"),
    FINISH("已完成"),
    INVALID("作废"),
    MODIFIED("已修改"),
    GIVE("赠送"),
    REFUND("外卖退款");

    private String name;

    OrderStatusEnum(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    private static final Map<String, OrderStatusEnum> nameMap = new HashMap<>();

    static {
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            nameMap.put(statusEnum.getName(), statusEnum);
        }
    }

    public static OrderStatusEnum getByName(String name) {
        if (StrUtil.isBlank(name)) {
            return INIT;
        }
        return nameMap.getOrDefault(name, INIT);
    }
}